//
//  PersonPackageCell.m
//  Gene
//
//  Created by 小震GG on 2019/10/10.
//  Copyright © 2019 小震GG. All rights reserved.
//

#import "PersonPackageCell.h"

@interface PersonPackageCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *logoImage;
@property (nonatomic, strong) UILabel *nameLB;
@property (nonatomic, strong) UILabel *contentLB;
@property (nonatomic, strong) UILabel *priceLB;
@property (nonatomic, strong) UIButton *buyBtn;

@end

@implementation PersonPackageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = NO;
        
        [self setView];
    }
    
    return self;
}

- (void)setView
{
    self.bgView = [[UIView alloc]initWithFrame:CGRectMake(25, 6, kWindowW-50, 110)];
    [self addSubview:self.bgView];
    self.bgView.backgroundColor = [UIColor whiteColor];
    self.bgView.layer.cornerRadius = 6.0;
    self.bgView.layer.shadowColor = [UIColor colorWithHEX:@"6E6E6E"].CGColor;
    self.bgView.layer.shadowOffset = CGSizeMake(0, 0);
    self.bgView.layer.shadowOpacity = 0.21;
    
    self.logoImage = [[UIImageView alloc]initWithFrame:CGRectMake(8, 14, 97, 82)];
    [self.bgView addSubview:self.logoImage];
    self.logoImage.image = ImageName(@"k_logo");
    self.logoImage.clipsToBounds = YES;
    self.logoImage.contentMode = UIViewContentModeScaleAspectFill;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.logoImage.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(7.5, 7.5)];
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = self.logoImage.bounds;
    maskLayer.path = maskPath.CGPath;
    self.logoImage.layer.mask = maskLayer;
    
    self.nameLB = [[UILabel alloc]init];
    [self.bgView addSubview:self.nameLB];
    [self.nameLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(114);
        make.right.equalTo(-15);
        make.top.equalTo(14);
    }];
    self.nameLB.textColor = tThreeColor;
    self.nameLB.font = kFont(13);
    
    self.contentLB = [[UILabel alloc]init];
    [self.bgView addSubview:self.contentLB];
    [self.contentLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLB.mas_left);
        make.right.equalTo(-15);
        make.top.equalTo(self.nameLB.mas_bottom).offset(12);
        make.height.lessThanOrEqualTo(50);
    }];
    self.contentLB.textColor = [UIColor colorWithHEX:@"#9FB0BD"];
    self.contentLB.font = kFont(11);
    self.contentLB.numberOfLines = 0;
    
    self.priceLB = [[UILabel alloc]init];
    [self.bgView addSubview:self.priceLB];
    [self.priceLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLB.mas_left);
        make.bottom.equalTo(-11);
    }];
    self.priceLB.textColor = [UIColor colorWithHEX:@"#FF0000"];
    self.priceLB.font = kFont(13);

    self.buyBtn = [[UIButton alloc]init];
    [self.bgView addSubview:self.buyBtn];
    [self.buyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(-15);
        make.height.equalTo(22);
        make.bottom.equalTo(-8);
        make.width.equalTo(72);
    }];
    self.buyBtn.layer.masksToBounds = YES;
    self.buyBtn.layer.cornerRadius = 5.0;
    self.buyBtn.backgroundColor = tColor(@"F46D37");
    [self.buyBtn setTitle:LocalizationKey(@"立即购买") forState:UIControlStateNormal];
    [self.buyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.buyBtn.titleLabel.font = kFont(12);
    self.buyBtn.userInteractionEnabled = NO;
    
}

- (void)upDataModel:(NSDictionary *)model
{
    self.nameLB.text = [NSString stringWithFormat:@"%@",model[@"name"]];
    self.contentLB.text = [NSString stringWithFormat:@"%@",model[@"details"]];
    self.priceLB.text = [NSString stringWithFormat:@"%@ DWTT",[ToolUtil judgeStringForDecimalPlaces:[NSString stringWithFormat:@"%@",model[@"dwttPrice"]] point:4]];
    [self.logoImage sd_setImageWithURL:[NSURL URLWithString:model[@"img"]] placeholderImage:ImageName(@"k_logo")];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
